// http protocol, uses for Http protocol functions.
//
#pragma once
#include "HttpException.h"

namespace HttpProtocol
{

class CHttpConnect;

class CHttpStream
{
public:
	CHttpStream(HINTERNET hFile, LPCSTR pstrVerb, LPCSTR pstrObject,
		CHttpConnect* pConnection);
	~CHttpStream(void);

public:
	BOOL AddRequestHeaders(LPCSTR pstrHeaders,
		DWORD dwFlags = HTTP_ADDREQ_FLAG_ADD_IF_NEW,
		int dwHeadersLen = -1);

	BOOL SendRequest(LPCSTR lpszHeaders, 
		DWORD dwHeadersLength,
		LPVOID lpOptional,
		DWORD dwOptionalLength);

	BOOL ReadStream(LPVOID lpBuffer,
		DWORD dwNumberOfBytesToRead,
		LPDWORD lpdwNumberOfBytesRead);

	BOOL SendRequestEx(DWORD dwTotalLen,
		DWORD dwFlags = HSR_INITIATE,
		DWORD_PTR dwContext = 1);

	BOOL WriteString(LPCSTR pstr);

	BOOL EndRequest(DWORD dwFlags = 0,
		LPINTERNET_BUFFERS lpBuffIn = NULL,
		DWORD_PTR dwContext = 1);

	BOOL QueryInfoStatusCode(DWORD& dwStatusCode) const;

	BOOL QueryInfo(DWORD dwInfoLevel,
		LPVOID lpvBuffer, LPDWORD lpdwBufferLength, LPDWORD lpdwIndex = NULL) const;

	DWORD GetLength() const;

	BOOL Release();

private:
	HINTERNET m_hFile;
};

}